﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SuperFox.SuperServiceReference;

namespace SuperFox
{
    public partial class GoodCall : UserControl
    {

        private SuperServiceClient client;

        public GoodCall()
        {
            InitializeComponent();
        }

        private void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            bool ok = true;

            if (!NameTb.Validate())
                ok = false;

            if (!CompanyTb.Validate())
                ok = false;

            if (!PhoneTb.Validate())
                ok = false;

            if (!EmailTb.Validate())
                ok = false;

            if (!CompanyTb.Validate())
                ok = false;

            if (!ok)
            {
                MessageBox.Show("Please fill in all the required fields");
                return;
            }

            client = ServiceConfig.Connect();
            client.ContactUsCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(client_ContactUsCompleted);
            client.ContactUsAsync(NameTb.Text, PhoneTb.Text, EmailTb.Text, CompanyTb.Text, AddressTb.Text, CommentsTb.Text);
        }

        void client_ContactUsCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                MessageBox.Show("Message sent");
                (App.Current.RootVisual as MainPage).HyperlinkButton_Click((App.Current.RootVisual as MainPage).HomeLink, null);
            }
            else
            {

                MessageBox.Show("There was an error sending your message. Please try email your comments to adam@superfox.com.au");
            }
        }
    }
}
